# -*- coding: utf-8 -*-

# __date:       2021/7/10
# __author:     Yang Chao
# __function:


# 单向链表节点
class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None

    # 反转单链表
    def reverse(self, head):
        prev = None
        while head:
            temp = head.next
            head.next = prev
            prev = head
            head = temp
        return prev

# 双向链表节点
class DListNode:
    def __init__(self, val):
        self.val = val
        self.next = self.prev = None

    def reverse(self, head):
        cur = None
        while head:
            cur = head
            head = cur.next
            cur.next = cur.prev
            cur.prev = head
        return cur